﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HRSystem.DBAccess;
using HRSystem.Entity;
using HRSystem.Utility;

namespace HRSystem
{
    public partial class FormMDI : Form
    {
        private int childFormNumber = 0;

        private bool isExit = true;

        private Form CurrentForm;
        private FormSearch frmSearch;
        private FormSearchAndPrint frmSearchAndPrint;
        private FormPersonDetail frmPersonDetail;

        public FormMDI()
        {
            InitializeComponent();
        }

        #region Original Code
        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "窗口 " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            //DialogResult result = MessageBox.Show(ResourceCulture.GetString("main_exitMes"),ResourceCulture.GetString("message_message"),MessageBoxButtons.OKCancel);
            //if (result == DialogResult.OK)
            //{
            //isExit = false;
            this.Close();
            //}
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void loginOutToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void enToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void cnToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }
        #endregion


        private void ShowChild(Form frm)
        {
            CurrentForm = frm;

            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.ControlBox = false;
            frm.Show();
        }

        private void FormMDI_Load(object sender, EventArgs e)
        {
            this.Text = PageConst.BELONG_CHINESE_NAME;
            this.toolStripStatusLabel.Text = "@2013 " + PageConst.BELONG_ENGLISH_NAME + " Limited. All righs reserved.";

            btnAdd_Click(null, null);
        }

        private void FormMDI_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            PageCommon.DisposeForm(CurrentForm);
            if (frmPersonDetail == null || frmPersonDetail.IsDisposed)
            {
                frmPersonDetail = new FormPersonDetail(0, null);
            }
            ShowChild(frmPersonDetail);
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            PageCommon.DisposeForm(CurrentForm);
            if (frmSearch == null || frmSearch.IsDisposed)
            {
                frmSearch = new FormSearch();
            }
            ShowChild(frmSearch);
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            PageCommon.DisposeForm(CurrentForm);
            if (frmSearchAndPrint == null || frmSearchAndPrint.IsDisposed)
            {
                frmSearchAndPrint = new FormSearchAndPrint();
            }
            ShowChild(frmSearchAndPrint);
        }

        private void FormMDI_FormClosing(object sender, FormClosingEventArgs e)
        {

            if (isExit)
            {
                DialogResult re = PageCommon.ShowMessageByYesNo("你确定要退出程序吗？");
                if (re == DialogResult.Yes)
                {
                    isExit = false;
                    Application.Exit();
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }
    }
}
